define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'my/article/index',
                    add_url: 'my/article/add',
                    edit_url: 'my/article/edit',
                    addcollect_url: 'my/article/addcollect',
                    // del_url: 'my/article/del',
                    // multi_url: 'department/article/multi',
                    table: 'my',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'), sortable: true},
                        {field: 'createuser.nickname', title: __('创建人'), operate: 'LIKE'},
                        {field: 'title', title: __('名称'), operate: 'LIKE'},
                        {field: 'introduction', title: __('简介'), operate: 'LIKE'},
                        {field: 'source', title: __('来源'), operate: 'LIKE'},
                        {field: 'direction', title: __('从事方向'), operate: 'LIKE'},
                        {field: 'create_time', title: __('Createtime'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true},
                        {
                            field: 'buttons',
                            width: "120px",
                            title: __('按钮组'),
                            table: table,
                            operate: false,
                            events: Table.api.events.operate,
                            buttons: [
                                {
                                    name: 'addcollect',
                                    text: __('收藏'),
                                    title: __('收藏'),
                                    confirm: '确认收藏？',
                                    classname: 'btn btn-xs btn-primary btn-ajax',
                                    url: $.fn.bootstrapTable.defaults.extend.addcollect_url,
                                },
                            ],
                            formatter: Table.api.formatter.buttons
                        },
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});